package com.ptone.messagecenter.modules.msg.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ptone.messagecenter.common.base.PageForm;
import com.ptone.messagecenter.common.base.Result;
import com.ptone.messagecenter.common.utils.VerificationUtil;
import com.ptone.messagecenter.modules.msg.entity.MsgTemplate;
import com.ptone.messagecenter.modules.msg.service.MsgTemplateService;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 消息模板：前端控制器
 *
 * @author:Lance
 */
@RestController
@RequestMapping("/msgTemplate")
public class MsgTemplateController {

    @Resource
    private MsgTemplateService msgTemplateService;


    /**
     * 消息模板-insertOrUpdate
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/insertOrUpdate")
    public Result<Boolean> insertOrUpdate(@RequestBody MsgTemplate entity) throws BindException {
        VerificationUtil.checkNull(entity, "msgTemplate", "msgType");
        return Result.success(msgTemplateService.insertOrUpdate(entity));
    }

    /**
     * 消息模板-delete
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody MsgTemplate entity) throws BindException {
        VerificationUtil.checkNull(entity, "id");
        return Result.success(msgTemplateService.delete(entity));
    }

    /**
     * 消息模板-info
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/info")
    public Result<MsgTemplate> info(@RequestBody MsgTemplate entity) throws BindException {
        VerificationUtil.checkNull(entity, "id");
        return Result.success(msgTemplateService.info(entity));
    }

    /**
     * 消息模板-page
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/page")
    public Result<IPage<MsgTemplate>> page(@RequestBody PageForm<MsgTemplate> form) throws BindException {
        VerificationUtil.checkPage(form);
        return Result.success(msgTemplateService.page(form));
    }

}
